IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'RealmGetSubNodesAdmin')
	BEGIN
		DROP  Procedure  RealmGetSubNodesAdmin
	END

GO

CREATE Procedure RealmGetSubNodesAdmin
@SagaID Int,
@RealmID Int = Null
AS
If(@RealmID IS Null)
Begin
	Select 
	r.Title,
	r.RealmID
	From Realm r
	Where r.SagaID = @SagaID 
End
Else
	Begin
	Select 
	r.Title,
	r.RealmID
	From Realm r
	Where r.SagaID = @SagaID And r.ParentID = @RealmID

End